package org.tedu.day07springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.tedu.day07springmvc.pojo.dto.BmiDTO;
import org.tedu.day07springmvc.pojo.dto.UserDTO;

import java.text.DecimalFormat;

@Controller
public class BmiController {

    @RequestMapping("/bmi")
    @ResponseBody
    public String bmi(BmiDTO bmiDTO) {
        double result = bmiDTO.getWeight() / Math.pow(bmiDTO.getHeight() / 100, 2);
        System.out.println(bmiDTO + " bmi: " + new DecimalFormat("#.##").format(result));
        if (result < 18.5) {
            return "您偏瘦了！";
        }
        else if (result < 24) {
            return "您的身体很健康哦！";
        }
        else if (result < 27) {
            return "您稍微有点胖了！";
        }
        else {
            return "您太胖了，该减肥了！";
        }
    }
}
